﻿<navigation:PageView x:Class="Corina.Cydee.Apphub.Views.Measures.DeviceMessageView"
                     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                     xmlns:be="clr-namespace:Corina.Interactivity.Silverlight;assembly=Corina.Interactivity.Silverlight"
                     xmlns:controls="clr-namespace:Corina.Controls.Silverlight;assembly=Corina.Controls.Silverlight"
                     xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                     xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
                     xmlns:localViewmodel="clr-namespace:Corina.Cydee.Apphub.Viewmodels"
                     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                     xmlns:navigation="clr-namespace:Corina.Cydee.Apphub.Base"
                     xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
                     xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit"
                     Title="设备消息"
                     FontSize="14"
                     d:DesignHeight="480"
                     d:DesignWidth="900"
                     mc:Ignorable="d">
    <navigation:PageView.DataContext>
        <localViewmodel:DeviceMessageViewmodel />
    </navigation:PageView.DataContext>
    <Grid x:Name="LayoutRoot">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="auto" />
                <RowDefinition />
                <RowDefinition Height="auto" />
            </Grid.RowDefinitions>

            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="auto" />
                </Grid.ColumnDefinitions>
                <sdk:AutoCompleteBox ItemsSource="{Binding DeviceKindCollection}"
                                     MinimumPrefixLength="0"
                                     SelectedItem="{Binding SelectedDeviceKind,
                                                            Mode=TwoWay}"
                                     ValueMemberPath="Name"
                                     be:AutoCompleteBoxHelper.OtherPaths="Name,Description">
                    <sdk:AutoCompleteBox.ItemTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Name}" />
                        </DataTemplate>
                    </sdk:AutoCompleteBox.ItemTemplate>
                    <i:Interaction.Triggers>
                        <be:AutoCompleteBoxTrigger>
                            <be:ExecuteCommandAction Command="{Binding LoadCommand}" />
                        </be:AutoCompleteBoxTrigger>
                    </i:Interaction.Triggers>
                </sdk:AutoCompleteBox>
                <TextBlock Grid.Column="1"
                           VerticalAlignment="Center"
                           Text="  设备序列号：" />
                <TextBox Grid.Column="2" Text="{Binding DeviceSn, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
                    <i:Interaction.Triggers>
                        <be:TextBoxEnterKeyTrigger>
                            <be:ExecuteCommandAction Command="{Binding LoadCommand}" />
                        </be:TextBoxEnterKeyTrigger>
                    </i:Interaction.Triggers>
                </TextBox>
                <TextBlock Grid.Column="3"
                           VerticalAlignment="Center"
                           Text="  关键字：" />
                <TextBox Grid.Column="4" Text="{Binding Keywords, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
                    <i:Interaction.Triggers>
                        <be:TextBoxEnterKeyTrigger>
                            <be:ExecuteCommandAction Command="{Binding LoadCommand}" />
                        </be:TextBoxEnterKeyTrigger>
                    </i:Interaction.Triggers>
                </TextBox>

                <Button Grid.Column="5"
                        Width="24"
                        Height="24"
                        Margin="12,0"
                        HorizontalAlignment="Left"
                        Command="{Binding LoadCommand}"
                        Style="{StaticResource RefreshButton}" />

                <CheckBox Grid.Column="6"
                          VerticalAlignment="Center"
                          Content="检索所有条目"
                          IsChecked="{Binding SearchAll,
                                              Mode=TwoWay}" />
            </Grid>

            <toolkit:BusyIndicator Grid.Row="1"
                                   BusyContent="{StaticResource IDS_BUSYCONTENT_LOADING}"
                                   IsBusy="{Binding IsBusy}">
                <sdk:DataGrid Margin="0,12"
                              AutoGenerateColumns="False"
                              CanUserSortColumns="False"
                              IsReadOnly="True"
                              ItemsSource="{Binding ItemsCollection}">
                    <sdk:DataGrid.Columns>
                        <sdk:DataGridTextColumn Width="60"
                                                Binding="{Binding ItemIndex}"
                                                Header="序号" />
                        <sdk:DataGridTextColumn Width="120"
                                                Binding="{Binding DeviceSn}"
                                                Header="设备序列号" />
                        <sdk:DataGridTextColumn MinWidth="120"
                                                Binding="{Binding Kind}"
                                                Header="设备分类" />
                        <sdk:DataGridTextColumn Binding="{Binding MeasureTime, StringFormat=\{0:yyyy-MM-dd HH:mm tt\}}" Header="测量时间" />
                        <sdk:DataGridTextColumn Binding="{Binding Content}" Header="消息内容" />
                        <sdk:DataGridTextColumn Binding="{Binding ReceivedTime, StringFormat=\{0:yyyy-MM-dd HH:mm:ss tt\}}" Header="接收时间" />
                        <!--    -->
                        <sdk:DataGridTextColumn Width="120"
                                                Binding="{Binding UserName}"
                                                Header="用户名" />
                        <sdk:DataGridTemplateColumn Width="60" Header="解析">
                            <sdk:DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <StackPanel VerticalAlignment="Center">
                                        <TextBlock Foreground="{StaticResource HighlightBrush}"
                                                   Text="已解析"
                                                   Visibility="{Binding IsAnalysed,
                                                                        Converter={StaticResource BooleanToVisibilityConverter}}" />
                                        <Grid Visibility="{Binding IsAnalysed, Converter={StaticResource BooleanToVisibilityInverseConverter}}">
                                            <HyperlinkButton Content="解析"
                                                             Foreground="Red"
                                                             Visibility="{Binding Abnormal,
                                                                                  Converter={StaticResource BooleanToVisibilityInverseConverter}}">
                                                <i:Interaction.Triggers>
                                                    <i:EventTrigger EventName="Click">
                                                        <i:InvokeCommandAction Command="{Binding Path=DataContext.ResolveCommand, RelativeSource={RelativeSource AncestorType=navigation:PageView}}" CommandParameter="{Binding Id}" />
                                                    </i:EventTrigger>
                                                </i:Interaction.Triggers>
                                            </HyperlinkButton>
                                            <HyperlinkButton Content="异常"
                                                             Foreground="Red"
                                                             Visibility="{Binding Abnormal,
                                                                                  Converter={StaticResource BooleanToVisibilityConverter}}">
                                                <i:Interaction.Triggers>
                                                    <i:EventTrigger EventName="Click">
                                                        <i:InvokeCommandAction Command="{Binding Path=DataContext.ResolveCommand, RelativeSource={RelativeSource AncestorType=navigation:PageView}}" CommandParameter="{Binding Id}" />
                                                    </i:EventTrigger>
                                                </i:Interaction.Triggers>
                                            </HyperlinkButton>
                                        </Grid>


                                    </StackPanel>
                                </DataTemplate>
                            </sdk:DataGridTemplateColumn.CellTemplate>
                        </sdk:DataGridTemplateColumn>
                        <sdk:DataGridTemplateColumn Width="120" Header="操作">
                            <sdk:DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <StackPanel VerticalAlignment="Center" Orientation="Horizontal">
                                        <HyperlinkButton Content="详情">
                                            <i:Interaction.Triggers>
                                                <i:EventTrigger EventName="Click">
                                                    <i:InvokeCommandAction Command="{Binding Path=DataContext.ShowDetailCommand, RelativeSource={RelativeSource AncestorType=navigation:PageView}}" CommandParameter="{Binding Id}" />
                                                </i:EventTrigger>
                                            </i:Interaction.Triggers>
                                        </HyperlinkButton>
                                        <HyperlinkButton Margin="12,0" Content="删除">
                                            <i:Interaction.Triggers>
                                                <i:EventTrigger EventName="Click">
                                                    <i:InvokeCommandAction Command="{Binding Path=DataContext.RemoveCommand, RelativeSource={RelativeSource AncestorType=navigation:PageView}}" CommandParameter="{Binding Id}" />
                                                </i:EventTrigger>
                                            </i:Interaction.Triggers>
                                        </HyperlinkButton>
                                    </StackPanel>
                                </DataTemplate>
                            </sdk:DataGridTemplateColumn.CellTemplate>
                        </sdk:DataGridTemplateColumn>
                    </sdk:DataGrid.Columns>
                </sdk:DataGrid>
            </toolkit:BusyIndicator>

            <StackPanel Grid.Row="2"
                        HorizontalAlignment="Right"
                        Orientation="Horizontal">
                <Button Command="{Binding FirstPageCommand}" Style="{StaticResource FirstPageButtonStyle}" />
                <Button Margin="12,0"
                        Command="{Binding PreviousPageCommand}"
                        Style="{StaticResource PreviousPageButtonStyle}" />
                <TextBlock Margin="12,0" VerticalAlignment="Center">
                    <Run Text="{Binding Index}" />
                    <Run Text="/" />
                    <Run Text="{Binding PagesCount}" />
                </TextBlock>
                <Button Margin="12,0"
                        Command="{Binding NextPageCommand}"
                        Style="{StaticResource NextPageButtonStyle}" />
                <Button Command="{Binding LastPageCommand}" Style="{StaticResource LastPageButtonStyle}" />
            </StackPanel>
        </Grid>

        <controls:PromptDialog Title="详情"
                               HorizontalContentAlignment="Stretch"
                               VerticalContentAlignment="Stretch"
                               CloseCommand="{Binding CancelCommand}"
                               Visibility="{Binding ShowDetail,
                                                    Converter={StaticResource BooleanToVisibilityConverter}}"
                               WindowHeight="360"
                               WindowWidth="400">
            <Grid Margin="12,0">
                <Grid.RowDefinitions>
                    <RowDefinition />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <ScrollViewer>
                    <StackPanel>
                        <TextBlock Text="设备序列号" />
                        <TextBox IsReadOnly="True" Text="{Binding DetailEntity.DeviceSn}" />
                        <TextBlock Margin="0,12,0,0" Text="接收时间" />
                        <TextBox IsReadOnly="True" Text="{Binding DetailEntity.RecievedTime, StringFormat=\{0:yyyy-MM-dd HH:mm:ss tt\}}" />
                        <TextBlock Margin="0,12,0,0" Text="校验值" />
                        <TextBox IsReadOnly="True" Text="{Binding DetailEntity.ProofValue}" />
                        <TextBlock Margin="0,12,0,0" Text="内容" />
                        <TextBlock Text="{Binding DetailEntity.Content}" TextWrapping="Wrap" />
                        <TextBlock Margin="0,12,0,0" Text="源地址" />
                        <TextBox IsReadOnly="True" Text="{Binding DetailEntity.MobileOrIP}" />
                    </StackPanel>
                </ScrollViewer>
                <StackPanel Grid.Row="1"
                            HorizontalAlignment="Right"
                            Orientation="Horizontal">
                    <Button Width="60"
                            Margin="12,0"
                            Content="解析"
                            Visibility="{Binding DetailEntity.IsAnalysed,
                                                 Converter={StaticResource BooleanToVisibilityInverseConverter}}">
                        <i:Interaction.Triggers>
                            <i:EventTrigger EventName="Click">
                                <i:InvokeCommandAction Command="{Binding ResolveCommand}" CommandParameter="{Binding DetailEntity.Id}" />
                            </i:EventTrigger>
                        </i:Interaction.Triggers>
                    </Button>
                    <Button Width="60"
                            Command="{Binding CancelCommand}"
                            Content="取消" />
                </StackPanel>
            </Grid>
        </controls:PromptDialog>
    </Grid>
</navigation:PageView>
